<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <form action="" enctype="application/x-www-form-urlencoded"></form>
  <script type="text/text/javascript">
    // var xml=new XMLHttpRequest();
    // xml.open("POST","/lesson18");
    // xml.setRequestHeader("Content-Type","application/json");//对请求的头部数据进行一次内容格式的转换
    // xml.send(JSON.stringify({name:"leo"}));

    //也可以跟xml对象写成一个fetch方法，更为直观 简洁（底层是相同的）
    fetch("/lesson18",{
      method:"POST",//对应原来xml.open()
      headers:{
        "Content-Type":"application/json"
      },//对应原来的xml.setRequestHeader()
      body:JSON.stringify({name:"mingzhen"}); //对应的是原来xml.send(Form||string)
    }).then(res=>res.json()).then(result=>console.log(result));
       //对应原来的onreadystatechange()，用以接收服务器返回的数据
  </script>
</body>
</html>
